package pers.zff.web.common;

import java.util.ArrayList;
import java.util.List;

public class MessageInfo {
	
	List<String> error;
	List<String> warning;
	List<String> message;

	public MessageInfo() {
	}

	public static MessageInfo getInstance() {

		// if (messageInfo == null) {
		// synchronized (MessageInfo.class) {
		// if (messageInfo == null) {
		// messageInfo = new MessageInfo();
		// }
		// }
		// }
		return new MessageInfo();
	}

	public List<String> getError() {
		return error;
	}

	public void setError(List<String> error) {
		this.error = error;
	}

	public List<String> getWarning() {
		return warning;
	}

	public void setWarning(List<String> warning) {
		this.warning = warning;
	}

	public List<String> getMessage() {
		return message;
	}

	public void setMessage(List<String> message) {
		this.message = message;
	}

	public void putMessage(String msg) {
		if (null == this.getMessage()) {
			this.setMessage(new ArrayList<String>());
		}
		this.getMessage().add(msg);
	}

	public void putError(String msg) {
		if (null == this.getError()) {
			this.setError(new ArrayList<String>());
		}
		this.getError().add(msg);
	}

	public void putWarning(String msg) {
		if (null == this.getWarning()) {
			this.setWarning(new ArrayList<String>());
		}
		this.getWarning().add(msg);
	}

	public boolean hasError() {
		if (this.getError() != null && !this.getError().isEmpty()) {
			return true;
		}
		return false;
	}

	@Override
	public String toString() {
		return "MessageInfo [error=" + error + ", warning=" + warning + ", message=" + message + "]";
	}

}
